package com.potenza.training.resume.controller;

import com.potenza.training.resume.entity.SocialEntity;
import com.potenza.training.resume.service.SocialService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 社交主页
 *
 * @author lihonggang
 * @email lihonggang@gmail.com
 * @date 2021-07-15 20:23:25
 */
@RestController
@RequestMapping("resume/social")
public class SocialController {
    @Autowired
    private SocialService socialService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("resume:social:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = socialService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("resume:social:info")
    public R info(@PathVariable("id") Long id){
		SocialEntity social = socialService.getById(id);

        return R.ok().put("social", social);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("resume:social:save")
    public R save(@RequestBody SocialEntity social){
		socialService.save(social);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("resume:social:update")
    public R update(@RequestBody SocialEntity social){
		socialService.updateById(social);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("resume:social:delete")
    public R delete(@RequestBody Long[] ids){
		socialService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 回显
     */
    @RequestMapping("/findByresumeId/{resumeId}")
    @RequiresPermissions("resume:social:findByresumeId")
    public R findByresumeId(@PathVariable("resumeId") Integer resumeId){
        List<SocialEntity> socialList =  socialService.findByresumeId(resumeId);

        return R.ok().put("socialList",socialList);
    }

    /**
     * 删除单个
     */
    @RequestMapping("/deleteById/{id}")
    @RequiresPermissions("resume:social:deleteById")
    public R deleteById(@PathVariable("id") Integer id){
        socialService.removeById(id);

        return R.ok();
    }
}
